/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_Vertex_h__
#define __dylab_Vertex_h__

//===========================================================================================
#include <dylab/utils/geometry/Vector3.h>
#include <dylab/utils/containers/VectorObjContainer.h>

//===========================================================================================
namespace dylab {

    /** This class represents a boundary mesh vertex.
	*/
    class DYLAB_EXPORT Vertex
    {
    protected:
        uint32_t mIndex;
        Vector3	 mPosition;
        Vector3  mNormal;
        real_t   mTextureU;
        real_t   mTextureV;
        uint32_t mFaceNormalCounter;

    private:
        /// Non-initialized construction is not allowed.
        Vertex();
    public:
        Vertex(uint32_t _index, const Vector3 & _position, 
			const Vector3 & _normal = Vector3::ZERO, real_t _u = DYLAB_R(0), real_t _v = DYLAB_R(0));

        inline uint32_t getIndex() const
                { return mIndex; }

        inline Vector3 & position()
                { return mPosition; }
        inline const Vector3 & position() const
                { return mPosition; }

        inline Vector3 & normal()
                { return mNormal; }
        inline const Vector3 & normal() const
                { return mNormal; }
        
        void setTextureU(real_t _u)
                { mTextureU = _u; }                
        real_t getTextureU() const
                { return mTextureU; }
        
        void setTextureV(real_t _v)
                { mTextureV = _v; }                
        real_t getTextureV() const
                { return mTextureV; }

        void beginNormalCalculation();
        void addFaceNormal(const Vector3 & normal);
        void endNormalCalculation();
    };
    //-----------------------------------------------------------------------------

	//===========================================================================================
    class DYLAB_EXPORT VertexContainer
        : public VectorObjContainer<Vertex>
    {
    public:
        VertexContainer(bool _objectOwner)
            : VectorObjContainer<Vertex>(_objectOwner)
                { }
    };
    //-----------------------------------------------------------------------------

}
//===========================================================================================
#endif // __dylab_Vertex_h__
